// pages/category/category.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // isshow: 'none'
    isshow: false,//遮罩层和分类显示与否
    bookList: [
      {id:'001', name:"全部分类",children:[
        {id:'0001',name:"二级分类"},
        {id:'0001',name:"二级分类"},
        {id:'0001',name:"二级分类"},
        {id:'0001',name:"二级分类"},
        {id:'0001',name:"二级分类"},
      ]},
      {id:'002', name:"历史人文",children:[
        {id:'0001',name:"全部"},
        {id:'0002',name:"二级分类"},
      ]},
      {id:'003', name:"科普百科",children:[
        {id:'0001',name:"全部"},
        {id:'0002',name:"二级分类"},
        {id:'0003',name:"二级分类"},
        {id:'0004',name:"二级分类"},
        {id:'0005',name:"二级分类"},
        {id:'0006',name:"二级分类"},
        {id:'0007',name:"二级分类"},
        {id:'0008',name:"二级分类"},
      ]},
      {id:'004', name:"绘本故事",children:[
        {id:'0001',name:"全部"},
        {id:'0002',name:"英文绘本"},
        {id:'0003',name:"中文绘本"},
        {id:'0004',name:"二级分类"},
        {id:'0005',name:"二级分类"},
      ]},
      {id:'005', name:"绘本故事",children:[
        {id:'0001',name:"二级分类"},
        {id:'00014',name:"二级分类"},
        {id:'000144',name:"二级分类"},
        {id:'00014',name:"二级分类"},
        {id:'000156',name:"二级分类"},
      ]},
      {id:'006', name:"绘本故事",children:[
        {id:'0001',name:"二级分类"},
        {id:'0002',name:"二级分类"},
        {id:'0003',name:"二级分类"},
        {id:'0004',name:"二级分类"},
        {id:'0005',name:"二级分类"},
      ]},
    ],// 一级分类列表
    categroyId: '001',//当前选中的一级分类的id
    categroyName: '全部分类',//当前选中的一级分类的名称
    secondCategroy: '',//当前的一级分类下的二级分类 
    secondCategroyId: '0001'//当前的一级分类下的二级分类 id
  
  },
  //点击全部分类的回调
  changeMask(){
    let isshow = !this.data.isshow      
    this.setData({
      isshow
    })
  },
  //点击遮罩的回调
  handlemask(){
    this.setData({
      isshow: false,
      categroyName:this.categroyName
    })
    console.log('点击遮罩的回调');
  },
  //点击标签的回调
  handletag(){
    wx.showToast({
      title: '抱歉，暂无标签可选',
      icon:'none',
      duration:500
    })
  },
  //点击一级分类的回调
  onCategroy(event){
    console.log(event);
    let categroyId = event.currentTarget.dataset.id
    let categroyName = event.currentTarget.dataset.name
    this.categroyName = categroyName
    this.setData({
      categroyId
    })
    //将一级分类下的二级分类保存起来
    let secondCategroy = event.currentTarget.dataset.children
    console.log('点击的一级分类的名字为',this.categroyName);
    //关闭遮罩层并且更改当前的分类的名称
    this.setData({
      secondCategroy,
      categroyName:this.categroyName,
      isshow:false
    })

  },
  //点击二级分类的回调
  Onsecond(event){
    console.log('二级回调',event);
    let secondCategroyId = event.currentTarget.dataset.secondcategroyid
    console.log('二级分类id',secondCategroyId);
    this.setData({
      secondCategroyId
    })
  },
  //点击获取openID
  handleGetOpneID(){
    wx.login({
      success(res){
        console.log('获取openId成功',res);
      },
      fail(err){
        console.log('获取openId失败',err);
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // tabber切换
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1 // 数字是当前页面在tabbar的索引,如我的查询页索引是2，因此这边为2，同理首页就为0，消息中心页面为1
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})